package com.google.code.sip.ucenter.imports;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.code.sip.ucenter.dao.mongo.CreditTypeDaoImpl;
import com.google.code.sip.ucenter.model.CreditType;

@Service("creditTypeImporter")
public class CreditTypeImporter extends AbstractImporter<CreditType> {
	@Autowired
	private CreditTypeDaoImpl creditTypeDao;

	@Override
	protected CreditType toEntity(Map<String, String> props) {
		CreditType creditType = new CreditType();
		for (Map.Entry<String, String> entry : props.entrySet()) {
			String name = entry.getKey();
			String value = entry.getValue();
			try {
				if (entityClass.getDeclaredField(name) != null) {
					beanUtilsBean.copyProperty(creditType, name, value);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return creditType;
	}

	@Override
	protected void doSave(CreditType creditType) {
		creditTypeDao.save(creditType);
	}

	@Override
	protected void doInit() {
		creditTypeDao.clear();
	}
}
